﻿@model projectManagementWeb.Models.Manager.ManagerReportFormModel


@{
    ViewBag.Title = "ManagerReportForm";
}

<p align="right">
    @Html.ActionLink("<< Regresar", "Index")
</p>

<head>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">

    function enable(enabled) {
        if (enabled == true) {
            $('#units').show();
            $('#type').hide();
        }
        else {
            $('#units').hide();
            $('#type').show();
        }

        var isProjectListEmpty = @Html.Raw(Json.Encode(ViewBag.isProjectListEmpty));
        document.getElementById("ddlProject").disabled = isProjectListEmpty;

    }

    function updateProjectsID() {
        var idProject = $("#ddlProject").val();
        $.getJSON("/Manager/loadModulesByProjectID", { id: idProject },
					function (moduleData) {
					    var select = $("#ddlModule");
					    select.empty();

					    select.append($('<option/>', {
					        value: 0,
					        text: "-- Todos --"
					    }))
					    $.each(moduleData,
							function (index, itemData) {
							    if (itemData.Text != "Ninguno") {
							        select.append($('<option/>', { value: itemData.Value, text: itemData.Text }));
							    }
							});

					}
				);
        $("#ddlModule").val(0);
        //updateModel();
    };

    function updateResourcesID() {
        var idProject = $("#ddlProject").val();
        $.getJSON("/Manager/loadResourcesByProjectID", { id: idProject },
					function (resourceData) {
					    var select = $("#ddlResource");
					    select.empty();

					    select.append($('<option/>', {
					        value: 0,
					        text: "-- Todos --"
					    }))
					    $.each(resourceData,
							function (index, itemData) {
							    select.append($('<option/>', { value: itemData.Value, text: itemData.Text }));
							});

					}
				);
        $("#ddlResource").val(0);
        //updateModel();
    };

    function toggleDropDown() {


        if (document.getElementById("ddlModule").selectedIndex > 0) {
            document.getElementById("ddlResource").disabled = true;
        }
        if (document.getElementById("ddlResource").selectedIndex > 0) {
            document.getElementById("ddlModule").disabled = true;
        }
        if (document.getElementById("ddlModule").selectedIndex == 0) {
            document.getElementById("ddlResource").disabled = false;
        }
        if (document.getElementById("ddlResource").selectedIndex == 0) {
            document.getElementById("ddlModule").disabled = false;
        }
    }



    $(document).ready(

	function () {
	    updateProjectsID();
	    updateResourcesID();
	    $("#ddlProject").change(function () { updateProjectsID(); updateResourcesID(); });
	    //$("#ddlModule").change(function () { updateModel(); });

	    //updateDropDowns();
	}

);

</script>

</head>

<body onload="enable(true);">

@using (Html.BeginForm("ManagerReportForm", "Manager", FormMethod.Post))
{
    <div>
           <input type="submit" value="Generar Reporte" />
    </div>

    
    <div>
        <fieldset class="nested-Panel">
            <legend>Tipo de Reporte:</legend>
            <p>@Html.RadioButtonFor(m => m.reportType, "ValorGanado", new { @checked = true, @onClick = "enable(true);" }) Valor Ganado </p>
            <p>@Html.RadioButtonFor(m => m.reportType, "Tareas", new { @onclick = "enable(false);" }) Tareas en progreso</p>
        </fieldset>

        <fieldset class="nested-Panel" id="units">
            <legend>Unidades:</legend>
            <p>@Html.RadioButtonFor(m => m.units, "Porcentaje", new { @id = "uniRBP", @checked = true }) Por Porcentaje </p>
            <p>@Html.RadioButtonFor(m => m.units, "Horas", new { @id = "uniRBH" }) Por Horas de Construcción </p>
        </fieldset>

        <fieldset class="nested-Panel" id="type">
            <legend>Detalle:</legend>
            <p>@Html.RadioButtonFor(m => m.detail, "Individual", new { @id = "detailT", @name = "detailrep", @checked = true }) Tareas individuales </p>
            <p>@Html.RadioButtonFor(m => m.detail, "Total", new { @id = "detailI", @name = "detailrep" }) Total de tareas </p>
        </fieldset>
    </div>
    
    
    
    <div>
        
        <fieldset>
            <legend>Visibilidad:</legend>
            <p> Por Proyecto : <span style="position: absolute; left:210px"> @Html.DropDownListFor(m => m.projectID, new SelectList(ViewBag.projectList, "id", "name"), new { id = "ddlProject" }) </span></p>
            <p> Por Módulo   : <span style="position: absolute; left:210px"> @Html.DropDownListFor(m => m.moduleID, new SelectList(Enumerable.Empty<SelectListItem>(), "id", "name"), new { id = "ddlModule", @onChange = "toggleDropDown();" }) </span> </p>
            <p> Por Recurso  : <span style="position: absolute; left:210px"> @Html.DropDownListFor(m => m.resourceID, new SelectList(Enumerable.Empty<SelectListItem>(), "id", "name"), new { id = "ddlResource", @onChange = "toggleDropDown();" }) </span> </p>
        </fieldset>. 
    </div>
    
  
    
}
</body>

